package com.example.red_tea_house.moudle.Home.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.red_tea_house.R;
import com.example.red_tea_house.entity.setRecyclerViewNameBean;
import com.example.red_tea_house.moudle.Home.view.HomeFragment;

import java.util.List;

public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.HomeViewHolder>{

    private List<setRecyclerViewNameBean> data;
    private Context context;
    private View view;
    private int ImagePos;
    private HomeFragment homeFragment;


    public HomeAdapter(List<setRecyclerViewNameBean> data, Context context, HomeFragment homeFragment) {
        this.data = data;
        this.context =context;
        this.homeFragment=homeFragment;
    }

    @NonNull
    @Override
    public HomeAdapter.HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view= LayoutInflater.from(context).inflate(R.layout.fragment_home_item,parent,false);
        return new HomeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeAdapter.HomeViewHolder holder, int position) {
        holder.textView.setText(data.get(position).getName());
        switch (position){
            case 0:
                ImagePos =R.drawable.personal_space;
                break;
            case 1:
                ImagePos=R.drawable.collection_space;
                break;
            case 2:
                ImagePos=R.drawable.view_history;
                break;
            case 3:
                ImagePos=R.drawable.time_memory;
                break;
            case 4:
                ImagePos=R.drawable.setting;
        }
        holder.imageView.setImageResource(ImagePos);
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class HomeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView textView;
        ImageView imageView;

        public HomeViewHolder(@NonNull View itemView) {
            super(itemView);
            textView=view.findViewById(R.id.item_textview);
            imageView=view.findViewById(R.id.homePageItemImage);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            homeFragment.turnPage(textView.getText().toString());
        }
    }
}

